package poo.thread.counter;

public class Counter {
	private int val;

	public Counter(int val) {
		this.val = val;

	}

	private Object lock = new Object();

	public void incr() {
		synchronized (lock) {
			val++;
		}

	}

	// public synchronized void incr() {
	// val++;
	// }

	public void decr() {
		synchronized (lock) {
			val--;
		}
	}

	public int getVal() {
		synchronized (lock) {
			return val;
		}
	}

	public String toString() {
		synchronized (lock) {
			return "Counter val=" + val;
		}
	}
	
	
	
	
	
}// Counter
